package com.rest.demo.Controller;

import com.alibaba.fastjson.JSONObject;
import com.rest.demo.Service.DysmtBdc;
import com.rest.demo.util.Sm4Util;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;


@Data
@RestController
@RequestMapping("/DysmtHouse")//整个路由路径
public class GetUserHouse {

    @Value("${APiUrl.API_ROOT}")
    String API_ROOT;//定向网址值
    @Value("${APiUrl.DysmtBdcUrl}")
    String DysmtBdcUrl;//请求DysmtBdcUrl的主地址
    @Value("${APiUrl.DysmtBdcTestUrl}")
    String DysmtBdcTestUrl;//请求DysmtBdcTestUrl的主地址

    @RequestMapping("/DysmtHouseNameCard")//通过身份证及姓名查询
    public String getCode3(String QLRMC, String ZJH) throws IOException {

        String signature = "2b1bc547c38e58853706d0ba56e8cd13";//解密偏移量
        JSONObject params = new JSONObject();//创建一个JSON的请求参数

        params.put("QLRMC", QLRMC);//参数中设置不动产产权权利人
        params.put("ZJH", ZJH);//参数中设置不动产产权权利人证件号
        String decData = Sm4Util.dataEncrypt(JSONObject.toJSONString(params), signature);//加密【请求参数加密】

        JSONObject json = new JSONObject();//参数受理
        json.put("msgId", "c3ebe4f41a8a4566896a578403f156f4");
        json.put("areaCode", "511702");
        json.put("deptCode", "51000098008989080");
        json.put("deptName", "德阳市一窗受理");
        json.put("timestamp", "1607476387");
        json.put("encryptData", decData);
        DysmtBdc DysmtBdc = new DysmtBdc();
        String content = DysmtBdc.httpTest(json.toString(),DysmtBdcUrl);//请求后返回的结果 字符串类型
        String data = JSONObject.parseObject(content).getString("data");//转换为JSON后在读取Data里的数据【里面的数据是加密返回，需要解密可获得详细结果】
        String decDatacontent = Sm4Util.dataDecrypt(data, signature);//解密///
        System.out.println(decDatacontent);

        return decDatacontent;
    }


    @RequestMapping("/DysmtHouseId")//不动产产权证编号
    public String getCode4(String BDCQZH) throws IOException {


        String signature = "2b1bc547c38e58853706d0ba56e8cd13";//解密偏移量
        JSONObject params = new JSONObject();//创建一个JSON的请求参数
        params.put("BDCQZH", BDCQZH);//参数中设置不动产产权证编号

        String decData = Sm4Util.dataEncrypt(JSONObject.toJSONString(params), signature);//加密【请求参数加密】

        JSONObject json = new JSONObject();//参数受理
        json.put("msgId", "c3ebe4f41a8a4566896a578403f156f4");
        json.put("areaCode", "511702");
        json.put("deptCode", "51000098008989080");
        json.put("deptName", "德阳市一窗受理");
        json.put("timestamp", "1607476387");
        json.put("encryptData", decData);
        DysmtBdc DysmtBdc = new DysmtBdc();
        String content = DysmtBdc.httpTest(json.toString(),DysmtBdcUrl);//请求后返回的结果 字符串类型
        String data = JSONObject.parseObject(content).getString("data");//转换为JSON后在读取Data里的数据【里面的数据是加密返回，需要解密可获得详细结果】
        String decDatacontent = Sm4Util.dataDecrypt(data, signature);//解密///
        System.out.println(decDatacontent);
        return decDatacontent;
    }






//
//    @RequestMapping("/House")
//    public void GetHouse() {
//        System.out.println("不动产");
//        Dysmtl hh = new Dysmtl();
//        hh.postForObjectForm2();
//    }
//
//
    @RequestMapping("/Code")
    public String getCode() {
        String signature = "2b1bc547c38e58853706d0ba56e8cd13";
        JSONObject params = new JSONObject();
//        params.put("BDCQZH","2014090901229");
        params.put("QLRMC", "德阳市建设投资有限公司");
        params.put("ZJH", "91510600717543870B");

        String decData = Sm4Util.dataEncrypt(JSONObject.toJSONString(params), signature);//加密

        String decData2 = Sm4Util.dataDecrypt(decData, signature);//解密//
        System.out.println(decData2);
        return decData2;
    }

//
//    @RequestMapping("/Code2")
//    public String getCode2() {
//        String signature = "2b1bc547c38e58853706d0ba56e8cd13";
//        String hh = "30d848b9ed0a6cdf20de491c720e719dccd72c4f646d6ccfab085d9b9d36ee9e69d5718202e8bcdc02b3a093beba993f4fe7669a7492a38de84fa6688ceb41c808c1439b5dd2c3ee3bd41ef1cdaacb99b50a8b21c8b866e131c48e963e7f9a0f678da37d5a107bba34be3d316e5aeff7ab92d0140c7d7447372c3260fca7c5623ada774c4ab773754269a32a776d7b1573551c292f08475da47324f23fdae585f3f4165d566b2f0cce44b4f48cd07c315f304c060377996c826fe11dfd4fde3638fb14d12b7a01f40f4479f78f9b5bb248681181928e9f4f982f95d175278b7c60ace0c4096c367bda571c4561b934c5e828f3d5b6924d0cf618aa467964e1b4248b252e66972dfb05a3d1e75e4e8d2a3ee4c5399e7d96a4d181c943f03796e7420227544fb91979b8e1ec70f39a5710b8c9c4ef36de7f69f6b64380a77e64ce8e414e7724a062ba5f7497269fd67011523257241dc0b57ac1c960f90e2d9f262cabd1077656a84e4a2cbb468ebd11f44110de6e1395a3f24750be85c7eb481bc8c31ac601476cb6b20c4e666b2e5b2ec18ff3dfe2df24c8a600cdc6dc6e6c73cf08348cbbfa5e6baae15839c74b9ef17a5319bc36f65aa5625d47a6cf22305d759ac0ef1ed447e4a4cfe834bb9b4014db27313e0bb6242e42daeb4ad8b017e71a54fd99f621df0be66757d1d4d06bef1fb2588244407e368c5689e2896c326b21536b2f89e6d6f4c84477f2ca1e642e9df456bf8a6918b1ab087bd3177a73f2bc43078a60183e2fae44d34718b0339d71eef55e11bf630e0dec3367cda164de9b27d87bc90149b2487b081b1b5c676374d0eaffa968a85130a2184d94da43af8bc71ff1c794c888dc17f087960b0f1ad836e0d4aecf1a2cd2e50ef1eb5c0fef81cd5d91a35290a12ef395807529ddbf143eec29bcacae1ca2e6d29bc8f40bf371fe5cd9344fe78aa55968a9499bb8080b47c2c6372a4fb67c8f65ed61523bfcae0265f356c2e54a48e4f2a7afeca4d68a39f2221f804e107d6c8433d2d582f012b1a25adb2bb6b759f3bcc8b48441343577e535472a29f929bf5541d0ca2530ec75a550ad0fba54e0197e05a6d96f7307f14b988e63def747daa2651a24b490c18ff3dfe2df24c8a600cdc6dc6e6c73cf08348cbbfa5e6baae15839c74b9ef1e80e4b7ed3e724f296dd277bbbdd9cf0865c62cbe2e17b94ce82f8a2dd3f1ff32006d50aef5aad8801457eb1c87cbb3f46fc311f54947a1828ecaab55e31d2ceca646e53480310757cdc547c6687d23d15e2c9a1bf19307ccd4aad6946b185be731dfcaed839b3c53c649ff708f26256ad1d52f5a4f0d35c9535ab93ca87568fdc63cb6514cf8ca359b9493e170d2a783e7272d5ff2701f8ddef378a99fe13d270d20b3b064f25ed415453f1550c2a27ba30d8df23dd049a0408a221936dbda2bb5e2ad2dcfb61f38c869ec7f33ffe47e2e3c33c1fc7f4ebff6217ccf89f7cc7689f66b1c33d25269d6a03d7cc76b717929713c6221871dfdafc0e070859134db5e884627816e011e1eb6fb9001490c5d7442d37f4d1964e380ea4c9b5b3c314c6c127678e107ac1571481a3fcaad530df07cb18421a83ed49b02f91c7f65b26d1d70594b1e5079a7d3a43a1321d0424636edb46271539cef88ec8250a455c94908413c0e0f7166e6136baa0d74cccdba6aeaf0dc41424902eeee6f4dae3725e39bb1be6586192a82700780ece377982f9ff365a7cd2d1cc05d00cf4bff31947235b117fb311d9db7e039eca235d5c5711a36c03c616781ce313ae346ceb7d4bd7d56441b7ae7f0d2d5f0ba1dc5dd4e1ed0c2b9b4229238ae5af1d1c81eda588e248484e5bc618ec3d1a68b0230b2279b3ae402be909b88b45aba889fb31d85e2114d0edbfb21cd1e60a49a04a6060556110729cbbab1663d28ad20223c8036a96526b92abd1c61b5543e71bfdd5ff8b80bbca01cfa6f1a879adb488fbdb11d87ca144ba6549919a37ba44dd37e6c96b40810474a5f155b973f07f9b7c7140ec5a37c44f7a08526375c4f6d11a7750133ceaf1e57e6e75102504900d390502c538bd0ce8954abffbc95c574de4a0525c44705abbd7b4f69179d061e72339b6277275bb438882a9922eabfe1dac991f2c2383e6e2389a19dc19083a1079cd4c738356981f5499e3f39b4b1ebb24822097831de8ee3cead60cefb49b198ed8d43f2c904eef058d0f89abab22406193b4c77734ee2c0d97d59ee31a9e830dd6cf09c86b5bafe225b1e5c98fa699934a0efca7482cf5db8916cffb0f9a33be186a1db84470782b35f82c5312883865ce27433a128fcfb998b33fd51d507442663461c885561bf618a090c4917975a3a3c966f061d555a4bb02b88750cbc0934b448a8e7e7aec212d8984101a2424f468ed4fc296f987544da9b9e1dec8fb0145a355ac0ad19b3c90d6140fd407c510c496f255277319c7b7d622a6312e597883b304dbcf3fafd9addfc5bb0a992b1a1a03b91a54fd99f621df0be66757d1d4d06bef7602301acf1986a368a6a205152dc409dcaeb7cf78f75f8d1951386b2bc0c57a9ea6a0f6b47cf3c33ee6d3ba78d76b179094946f720541947cb291674c9b12a30369c9d02e1bf9e95445f404f9ad467d96b93eed361ec75d08246a885f90be7e";
//        String decData = Sm4Util.dataDecrypt(hh, signature);//解密///
//        System.out.println(decData);
//        return decData;
//    }
//
}
